package com.online_vote_system.demo.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.online_vote_system.demo.mapper.CompetitionMapper;
import com.online_vote_system.demo.vo.Competition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompetitionServiceImpl extends ServiceImpl<CompetitionMapper, Competition> implements CompetitionService {

    @Autowired
    CompetitionMapper competitionMapper;

    @Override
    public List<Competition> getAll() {
        return competitionMapper.getAll();
    }

    @Override
    public Competition getOne(String comId) {
        return competitionMapper.getOne(comId);
    }

    @Override
    public Competition getOneByType() {
        return competitionMapper.getOneByType();
    }

    @Override
    public void changeType(String type,String comId) {
        if (type.equals("0")){
            competitionMapper.changeZero();
            competitionMapper.changeOne(comId);
        }else {
            competitionMapper.changeOnlyZero(comId);
        }
    }

    @Override
    public void updateOne(String comId, String playerId_1, String playerId_2, String score1, String score2,String comName) {
        competitionMapper.updateOne(comId,playerId_1,playerId_2,score1,score2,comName);
    }

    @Override
    public void insertOne(String playerId_1, String playerId_2,String comName) {
        competitionMapper.insertOne(playerId_1,playerId_2,comName);
    }

}
